package com.bytedance.common.plugin.interfaces.pushmanager.classhandle;

import java.lang.reflect.Field;

public class Smith {
    private Field field;
    private String fieldName;
    private boolean inited;
    private Object obj;

    public Smith(Object arg3, String arg4) {

        if (arg3 == null) {
            throw new IllegalArgumentException("obj cannot be null");
        }

        this.obj = arg3;
        this.fieldName = arg4;
    }

    public Object get() throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
        this.prepare();
        if (this.field == null) {
            throw new NoSuchFieldException();
        }

        try {
            return this.field.get(this.obj);
        } catch (ClassCastException v0) {
            throw new IllegalArgumentException("unable to cast object");
        }
    }

    private void prepare() {
        if (!this.inited) {
            this.inited = true;
            Class v1 = this.obj.getClass();
            while (true) {
                if (v1 == null) {
                    return;
                }

                try {
                    Field v0_2 = v1.getDeclaredField(this.fieldName);
                    v0_2.setAccessible(true);
                    this.field = v0_2;
                    break;
                } catch (Exception v0_1) {
                    v1 = v1.getSuperclass();
                    continue;
                }
            }

            v1.getSuperclass();
        }
    }

    public void set(Object arg3) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
        this.prepare();
        if (this.field == null) {
            throw new NoSuchFieldException();
        }

        this.field.set(this.obj, arg3);
    }
}

